<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>势能迭代恢复打卡系统</title>
  <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
      background: #f5f5f7;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }

    .card {
      background: #fff;
      border-radius: 20px;
      box-shadow: 0 4px 20px rgba(0,0,0,0.1);
      padding: 30px;
      text-align: center;
      width: 320px;
    }

    h2 {
      font-size: 20px;
      color: #333;
      margin-bottom: 20px;
    }

    .progress-ring {
      position: relative;
      width: 150px;
      height: 150px;
      margin: 0 auto 20px;
    }

    .progress-ring svg {
      transform: rotate(-90deg);
      width: 100%;
      height: 100%;
    }

    .progress-ring circle {
      fill: none;
      stroke-width: 12;
      stroke-linecap: round;
    }

    .progress-ring .bg {
      stroke: #e5e5ea;
    }

    .progress-ring .progress {
      stroke: url(#grad);
      stroke-dasharray: 440; /* 周长 */
      stroke-dashoffset: 440;
      transition: stroke-dashoffset 0.5s ease;
    }

    .progress-text {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 24px;
      font-weight: 600;
      color: #333;
    }

    .btn {
      display: inline-block;
      margin: 8px;
      padding: 10px 20px;
      font-size: 15px;
      border-radius: 12px;
      border: none;
      cursor: pointer;
      font-weight: 500;
      transition: 0.2s;
    }

    .btn-primary {
      background: #007aff;
      color: white;
    }

    .btn-primary:hover {
      background: #005bbb;
    }

    .btn-secondary {
      background: #f2f2f7;
      color: #333;
    }

    .btn-secondary:hover {
      background: #e5e5ea;
    }
  </style>
</head>
<body>
  <div class="card">
    <h2>势能迭代打卡</h2>
    <div class="progress-ring">
      <svg>
        <defs>
          <linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="0%">
            <stop offset="0%" stop-color="#34c759"/>
            <stop offset="100%" stop-color="#30d158"/>
          </linearGradient>
        </defs>
        <circle class="bg" cx="75" cy="75" r="70"></circle>
        <circle class="progress" cx="75" cy="75" r="70"></circle>
      </svg>
      <div class="progress-text" id="progressText">0%</div>
    </div>
    <button class="btn btn-primary" onclick="increment()">打卡</button>
    <button class="btn btn-secondary" onclick="exportJSON()">导出JSON</button>
    <button class="btn btn-secondary" onclick="importJSON()">导入JSON</button>
  </div>

  <script>
    let progress = 0;
    let maxProgress = 10; // 打卡满的次数
    let history = [];

    const circle = document.querySelector('.progress');
    const text = document.getElementById('progressText');
    const circumference = 2 * Math.PI * 70; // 周长

    circle.style.strokeDasharray = circumference;
    circle.style.strokeDashoffset = circumference;

    function updateProgress() {
      let percent = Math.min((progress / maxProgress) * 100, 100);
      let offset = circumference - (percent / 100) * circumference;
      circle.style.strokeDashoffset = offset;
      text.textContent = Math.round(percent) + "%";
    }

    function increment() {
      if (progress < maxProgress) {
        progress++;
        history.push(progress);
        updateProgress();
      }
    }

    function exportJSON() {
      const data = JSON.stringify({progress, history});
      const blob = new Blob([data], { type: 'application/json' });
      const url = URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = '打卡历史.json';
      a.click();
      URL.revokeObjectURL(url);
    }

    function importJSON() {
      const fileInput = document.createElement('input');
      fileInput.type = 'file';
      fileInput.accept = '.json';
      fileInput.onchange = function(e) {
        const file = e.target.files[0];
        if (file) {
          const reader = new FileReader();
          reader.onload = function(event) {
            try {
              const data = JSON.parse(event.target.result);
              progress = data.progress || 0;
              history = data.history || [];
              updateProgress();
            } catch (err) {
              alert('导入文件格式错误');
            }
          };
          reader.readAsText(file);
        }
      };
      fileInput.click();
    }

    // 初始化
    updateProgress();
  </script>
</body>
</html>
